using System;
using System.Collections.Generic;
using System.Linq;

namespace Karma.Framework.Core.Domain.Tools.Import.Configuration.Fluent
{
    public class EntityConfiguration
    {
        public EntityConfiguration(Type mytype)
        {
            _type = mytype;
        }

        private IList<PropertyConfiguration> _properties = new List<PropertyConfiguration>();
        public PropertyConfiguration[] Properties
        {
            get
            {
                return _properties.ToArray();
            }
        }

        private string _alias;
        public string Alias
        {
            get
            {
                if (string.IsNullOrEmpty(_alias))
                {
                    return _type.Name;
                }
                return _alias;
            }
            internal set
            {
                _alias = value;
            }
        }

        private Type _type;
        public Type Type
        {
            get
            {
                return _type;
            }
        }

        public string FullName
        {
            get
            {
                return _type.FullName;
            }
        }

        public void AddProperty(PropertyConfiguration property)
        {
            _properties.Add(property);
        }

        private Type _persister;
        public Type Perister
        {
            get
            {
                return _persister;
            }
            internal set
            {
                _persister = value;
            }
        }

        private List<Type> _listeners = new List<Type>();
        public Type[] Listeners
        {
            get
            {
                return _listeners.ToArray();
            }
        }

        private Type _validator;
        public Type Validator
        {
            get
            {
                return _validator;
            }
            internal set
            {
                _validator = value;
            }
        }

        private bool _replaceDefaultValidator;
        public bool ReplaceDefaultValidator
        {
            get
            {
                return _replaceDefaultValidator;
            }
            internal set
            {
                _replaceDefaultValidator = value;
            }
        }

        public bool HasValidator
        {
            get
            {
                return _validator != null;
            }
        }

        public bool HasPersister
        {
            get
            {
                return _persister != null;
            }
        }

        public void AddListener(Type listener)
        {
            _listeners.Add(listener);
        }
    }
}